//
//  MianTabBarController.swift
//  01-微博项目搭建
//
//  Created by Adolph on 15/5/14.
//  Copyright (c) 2015年 Adolph. All rights reserved.
//

import UIKit

class MianTabBarController: UITabBarController {
   
    @IBOutlet weak var mianTbaBar: MianTabBar!
    
    override func viewDidLoad() {
        addChildViewControllers()
        
        //添加按钮的点击事件
        mianTbaBar.composedButton.addTarget(self, action: "composeBlick", forControlEvents: UIControlEvents.TouchUpInside)
        
    }
    
    ///item中间按钮的点击事件
    func composeBlick(){
       
          let sb = UIStoryboard(name: "Compose", bundle: nil)
          let vc = sb.instantiateInitialViewController() as! UIViewController
         presentViewController(vc, animated: true, completion: nil)
    
    }
    
    
    ///添加所有子控制器
    func addChildViewControllers(){
        
        tabBar.tintColor = UIColor.orangeColor()
        
        addChildViewController("HomeTableViewController", "首页", "tabbar_home")
        addChildViewController("MessageTableViewController", "消息", "tabbar_message_center")
        addChildViewController("DiscoverTableViewController", "发现", "tabbar_discover")
        addChildViewController("ProfileTableViewController", "我", "tabbar_profile")
    
    }
    
    ///添加自控制器
    func addChildViewController(sbName:String, _ title: String, _ imageName: String){
      
        let sb = UIStoryboard(name: sbName, bundle: nil)
        
        let nav = sb.instantiateInitialViewController() as! UINavigationController
        
        nav.title = title
        nav.topViewController.title = title
        nav.tabBarItem.image = UIImage(named: imageName)
        nav.tabBarItem.selectedImage = UIImage(named: imageName + "_highlighted")
        
        //把导航栏控制器添加到tabBar视图
        addChildViewController(nav)
    }
    
}
